package com.itHuangTao.tank.collisions;

import com.almasb.fxgl.dsl.FXGL;
import com.almasb.fxgl.entity.Entity;
import com.almasb.fxgl.physics.CollisionHandler;
import com.itHuangTao.tank.GameType;
import com.itHuangTao.tank.TankApp;
import com.itHuangTao.tank.components.FlagComponent;
import com.itHuangTao.tank.ui.FailedScene;

public class BulletFlagHandler extends CollisionHandler {
    public BulletFlagHandler() {
        super(GameType.BULLET, GameType.FLAG);
    }

    @Override
    protected void onCollisionBegin(Entity bullet, Entity flag) {
        flag.getComponent(FlagComponent.class).onHit();
        FXGL.spawn("explode", bullet.getCenter().subtract(50 / 2.0, 50 / 2.0));
        bullet.removeFromWorld();
        //调用游戏结束方法
        FXGL.<TankApp>getAppCast().gameOver();
    }
}
